|
1
|
|
|
import React, { FunctionComponent, useState } from "react" |
|
2
|
|
|
|
|
3
|
|
|
import { graphql, useStaticQuery } from "gatsby" |
|
4
|
|
|
import axios from "axios" |
|
5
|
|
|
import "./MatchesSlider.scss" |
|
6
|
|
|
|
|
7
|
|
|
import Slider, { LazyLoadTypes } from "react-slick" |
|
8
|
|
|
import { useEffect } from "react" |
|
9
|
|
|
import { MatchTeaserDetail } from "./MatchTeaser" |
|
10
|
|
|
import Spinner from "./Spinner" |
|
11
|
|
|
|
|
12
|
|
|
const MatchesSlider: FunctionComponent = () => { |
|
13
|
|
|
const [data, setData] = useState<Match[]>([]) |
|
14
|
|
|
|
|
15
|
|
|
const { |
|
16
|
|
|
site: { |
|
17
|
|
|
siteMetadata: { kcvvPsdApi }, |
|
18
|
|
|
}, |
|
19
|
|
|
}: MatchesQueryData = useStaticQuery(graphql` |
|
20
|
|
|
{ |
|
21
|
|
|
site { |
|
22
|
|
|
siteMetadata { |
|
23
|
|
|
kcvvPsdApi |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
`) |
|
28
|
|
|
|
|
29
|
|
|
const settings_slickslider = { |
|
30
|
|
|
slidesToShow: 4, |
|
31
|
|
|
slidesToScroll: 1, |
|
32
|
|
|
dots: false, |
|
33
|
|
|
arrows: true, |
|
34
|
|
|
centerMode: true, |
|
35
|
|
|
focusOnSelect: true, |
|
36
|
|
|
infinite: true, |
|
37
|
|
|
lazyLoad: `progressive` as LazyLoadTypes, |
|
38
|
|
|
|
|
39
|
|
|
responsive: [ |
|
40
|
|
|
{ |
|
41
|
|
|
breakpoint: 1700, |
|
42
|
|
|
settings: { |
|
43
|
|
|
slidesToShow: 4, |
|
44
|
|
|
}, |
|
45
|
|
|
}, |
|
46
|
|
|
{ |
|
47
|
|
|
breakpoint: 1400, |
|
48
|
|
|
settings: { |
|
49
|
|
|
slidesToShow: 3, |
|
50
|
|
|
}, |
|
51
|
|
|
}, |
|
52
|
|
|
{ |
|
53
|
|
|
breakpoint: 1200, |
|
54
|
|
|
settings: { |
|
55
|
|
|
slidesToShow: 2, |
|
56
|
|
|
}, |
|
57
|
|
|
}, |
|
58
|
|
|
{ |
|
59
|
|
|
breakpoint: 800, |
|
60
|
|
|
settings: { |
|
61
|
|
|
slidesToShow: 1, |
|
62
|
|
|
}, |
|
63
|
|
|
}, |
|
64
|
|
|
], |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
useEffect(() => { |
|
68
|
|
|
async function getData() { |
|
69
|
|
|
const response = await axios.get(`${kcvvPsdApi}/matches/next`) |
|
70
|
|
|
setData(response.data) |
|
71
|
|
|
} |
|
72
|
|
|
getData() |
|
73
|
|
|
}, []) |
|
74
|
|
|
|
|
75
|
|
|
return ( |
|
76
|
|
|
<div className="matches_slider__wrapper"> |
|
77
|
|
|
{data.length > 0 || <Spinner />} |
|
78
|
|
|
<Slider className={`matches_slider`} {...settings_slickslider}> |
|
79
|
|
|
{data |
|
80
|
|
|
.sort((a, b) => a.timestamp - b.timestamp) |
|
81
|
|
|
.map((match: Match, i) => { |
|
82
|
|
|
return ( |
|
83
|
|
|
<div className="matches_slider__item" key={i} data-equalizer-watch="true"> |
|
84
|
|
|
<MatchTeaserDetail match={match} /> |
|
85
|
|
|
</div> |
|
86
|
|
|
) |
|
87
|
|
|
})} |
|
88
|
|
|
</Slider> |
|
89
|
|
|
</div> |
|
90
|
|
|
) |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
export default MatchesSlider |
|
94
|
|
|
|